package main;
import ftp.FTPController;
import gui.MainFrame;
import it.sauronsoftware.ftp4j.FTPAbortedException;
import it.sauronsoftware.ftp4j.FTPDataTransferException;
import it.sauronsoftware.ftp4j.FTPException;
import it.sauronsoftware.ftp4j.FTPIllegalReplyException;

import java.io.File;
import java.io.IOException;
import java.util.Calendar;

import javax.swing.JFileChooser;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;

import mp3.MP3ConversionManager;

import org.xml.sax.SAXException;


public class Driver {
	
	static MainFrame mainFrame;
	
 
	public static String getLocalFolderPath() {
		return localFolderPath;
	}


	private static String localFolderPath;
	
	
	public static void main(String args[]) throws ParserConfigurationException, SAXException, IOException {
		   System.loadLibrary("libmp3lame");
		init();
	  mainFrame = new MainFrame();	
	  mainFrame.updateUSBList();
	
 
	}
	
	public static void updateUI() 
	{  
		mainFrame.update();
			 
	}		

	public static void processFile(File listCurrentlySelected, Calendar drop) throws IOException, IllegalStateException, FTPIllegalReplyException, FTPException, FTPDataTransferException, FTPAbortedException, TransformerException {
		
		MusicFile t = FileManager.addWaveToSysten( listCurrentlySelected,   drop);
		mainFrame.update();
		 MP3ConversionManager.mp3ConversionManager.convertToMp3(t);
 
		 XMLHandler.addMusicFile(t);
			FTPController.getInstance().send(t);
 
	}
	
	
	private static void init() throws ParserConfigurationException, SAXException, IOException {
				   localFolderPath =(new JFileChooser().getFileSystemView().
						   				getDefaultDirectory().getAbsolutePath()) + "\\Shakey";
				   
				   USBManager.loadUSBContent();
				   
				   for(MusicFile m : XMLHandler.parseXMLToMusicFileList(new File(localFolderPath + "\\musicfiles.xml")))
					   FileManager.addMusicFile(m);
				 
	}
}
 	